package cc.laop.sslsocket.server;

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class SSLSocketClient {

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();

            SSLSocket sslSocket = (SSLSocket) factory.createSocket("37.187.253.204", 8000);

            InputStream input = sslSocket.getInputStream();
            OutputStream output = sslSocket.getOutputStream();

            BufferedInputStream bis = new BufferedInputStream(input);
            BufferedOutputStream bos = new BufferedOutputStream(output);

            bos.write("Hello".getBytes());
            bos.flush();

            byte[] buffer = new byte[2048];
            int length = bis.read(buffer);
            System.out.println(new String(buffer, 0, length));

            sslSocket.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
